//
//  SDProvinceViewController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/6/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDProvinceViewController.h"
#import "SDCityModel.h"
#import "SDCityViewController.h"
#import "UIBarButtonItem+SDExtension.h"

@interface SDProvinceViewController ()<UITableViewDelegate, UITableViewDataSource>

//城市数组
@property (nonatomic, strong) NSArray<SDCityModel *> *citys;


@end

static NSString *const panvinceId = @"cell";

@implementation SDProvinceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self setUpLeftButtonItem];
}

- (void)setupUI {
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:panvinceId];
    
}
- (void)setUpLeftButtonItem{
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem initWithImageStr:@"JianTou" addTarget:self withAction:@selector(goBack)];
    
}

- (void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.citys.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:panvinceId forIndexPath:indexPath];
    SDCityModel *model = self.citys[indexPath.row];
    cell.textLabel.text = model.name;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SDCityModel *model = self.citys[indexPath.row];
    SDCityViewController *vc = [[SDCityViewController alloc] init];
    vc.cities = model.cities;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark
#pragma mark- 懒加载
- (NSArray<SDCityModel *> *)citys{
    if (_citys == nil) {
        _citys = [SDCityModel getArrModel];
    }
    return _citys;
}


@end
